const chalk = require('chalk');
const fse = require('fs-extra');
const path = require('path');
const log = console.log;

function getProjectResolve(projectPath) {
    return function(to) {
        return path.resolve(projectPath, to);
    }
}

function output(creation) {
    return new Promise((resolve, reject) => {
        const setting = creation._setting;
        const {
            name
        } = setting;
        const cwd = process.cwd();

        // 文件夹
        const projectPath = path.join(cwd, name);
        const projectResolve = getProjectResolve(projectPath);
        // 新建
        fse.mkdirSync(projectPath);
        // copy
        creation.copy('src', projectResolve('src'));
        creation.copy('build', projectResolve('build'));
        creation.copyTpl('package.json', projectResolve('package.json'), setting);
        //creation.copyTpl('build/webpack.base.conf.js', projectResolve('webpack.base.conf.js'), setting);

        creation._mfs.commit(() => {
            resolve();
        });
    });
}

module.exports = output;